define(['module', 'react', 'react-dom', '../BaseDemo', 'classnames', "../Tile", 'Label', 'Card', 'Button', 'jquery', 'business/TableForm'], function (module, React, ReactDOM, BaseDemo, classnames, Tile, Label, Card, Button, jQuery, TableForm) {
    'use strict';

    function _classCallCheck(instance, Constructor) {
        if (!(instance instanceof Constructor)) {
            throw new TypeError("Cannot call a class as a function");
        }
    }

    var _createClass = function () {
        function defineProperties(target, props) {
            for (var i = 0; i < props.length; i++) {
                var descriptor = props[i];
                descriptor.enumerable = descriptor.enumerable || false;
                descriptor.configurable = true;
                if ("value" in descriptor) descriptor.writable = true;
                Object.defineProperty(target, descriptor.key, descriptor);
            }
        }

        return function (Constructor, protoProps, staticProps) {
            if (protoProps) defineProperties(Constructor.prototype, protoProps);
            if (staticProps) defineProperties(Constructor, staticProps);
            return Constructor;
        };
    }();

    function _possibleConstructorReturn(self, call) {
        if (!self) {
            throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
        }

        return call && (typeof call === "object" || typeof call === "function") ? call : self;
    }

    function _inherits(subClass, superClass) {
        if (typeof superClass !== "function" && superClass !== null) {
            throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
        }

        subClass.prototype = Object.create(superClass && superClass.prototype, {
            constructor: {
                value: subClass,
                enumerable: false,
                writable: true,
                configurable: true
            }
        });
        if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
    }

    var Page = function (_BaseDemo) {
        _inherits(Page, _BaseDemo);

        function Page() {
            _classCallCheck(this, Page);

            return _possibleConstructorReturn(this, Object.getPrototypeOf(Page).apply(this, arguments));
        }

        _createClass(Page, [{
            key: 'addRow',
            value: function addRow() {
                this.refs.tableForm.addRow();
            }
        }, {
            key: 'removeRow',
            value: function removeRow() {
                this.refs.tableForm.removeRow(0);
            }
        }, {
            key: 'getData',
            value: function getData() {
                console.log(this.refs.tableForm.getData());
            }
        }, {
            key: 'onChange',
            value: function onChange(name, value, col, items, selectItem) {
                if (name === "loopDomain") {
                    items["checkURL"].setValue("http://" + value);
                }
            }
        }, {
            key: 'submit',
            value: function submit() {
                if (this.refs.tableForm.isValid()) {
                    //do submit
                }
            }
        }, {
            key: 'componentDidMount',
            value: function componentDidMount() {
                var table_form = ReactDOM.findDOMNode(this.refs.tableForm);

                var scope = this;
                $(table_form).on("click", ".delete-btn", function () {
                    var id = $(this).data("id");
                    console.log(scope.refs.tableForm.getRowData(id));
                });
            }
        }, {
            key: 'render',
            value: function render() {

                var columns = [{ name: "domain", type: "text", text: "域名", props: { required: true, placeholder: "www.baidu.com" } }, { name: "loopDomain", type: "textarea", text: "回源IP/回源域名", props: { required: true }, messages: { required: "请填写回源IP/回源域名" } }, { name: "checkURL", type: "textarea", text: "回源检测URL", props: { required: true } }, { name: "clientIP", type: "select", text: "获取客户端IP", props: { required: true, defaultValue: "1", data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }] } }, { name: "district", type: "select", text: "加速区域", props: { required: true, multi: true, data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }] } }, { name: "op", text: "操作", format: function format(value, col, row) {
                        return '<a href="javascript:void(0)" class="text-blue delete-btn" data-id="' + row.id + '"><i class="fa fa-trash"></i>删除</a>';
                    } }];
                return React.createElement(
                    'div',
                    { className: 'container' },
                    React.createElement(
                        Card,
                        { title: '表格form' },
                        React.createElement(TableForm, { ref: 'tableForm', columns: columns, className: 'form-table text-center', onChange: this.onChange.bind(this) }),
                        React.createElement(
                            'div',
                            { className: 'mt-25 text-center' },
                            React.createElement(
                                Button,
                                { theme: 'primary', onClick: this.submit.bind(this) },
                                '提 交'
                            )
                        ),
                        React.createElement(
                            'div',
                            { className: 'mt-20' },
                            React.createElement(
                                Button,
                                { onClick: this.addRow.bind(this) },
                                '添加'
                            ),
                            React.createElement(
                                Button,
                                { onClick: this.removeRow.bind(this) },
                                '删除'
                            ),
                            React.createElement(
                                Button,
                                { onClick: this.getData.bind(this) },
                                '获取数据'
                            )
                        )
                    )
                );
            }
        }]);

        return Page;
    }(BaseDemo);

    module.exports = Page;
});
